var vm = new Vue({
    el:"#app",
    data:{
        messages:'',
        pageModel:'',
        deptArea:''
    },
    methods:{
        getDeptList:function () {
            let deptName = $("input[name='deptName']").val();
            axios({
                method:'post',
                url:'/dept/queryDept',
                params:{"pageNum":1,"deptName":deptName}
                }).then(function(result){
                vm.pageModel = result.data;
                vm.messages=result.data.data;
            }).catch(function (err) {
                console.log(err);
            })
        },
        changePageNum:function (num) {
            let deptName = $("input[name='deptName']").val();
            axios({
                method:'post',
                url:'/dept/queryDept',
                params:{"pageNum":num,"deptName":deptName}
            }).then(function(result){
                vm.pageModel = result.data;
                vm.messages=result.data.data;
            }).catch(function (err) {
                console.log(err);
            })
        },
        getDeptArea:function () {
            axios.post("/dept/queryDeptArea").then(
                function(result){
                    vm.deptArea=result.data;
                    console.log(vm.deptArea);
                },function (err) {
                    console.log(err);
                }
            )
        }
    },
    //页面加载完自动执行
    mounted(){
        this.getDeptList();
    }
})

function toDeptInfo(t){
    let deptName = $(t).parent().siblings().eq(0).html();

    location.href = "../../../../templates/sysManage/deptManage/deptInfo.html?deptName=" + deptName;
}

function toUpdate(t){
    let deptName = $(t).parent().siblings().eq(0).html();

    location.href = "../../../../templates/sysManage/deptManage/deptUpdate.html?deptName=" + deptName;
}

function deleteDept(t){
    let deptName = $(t).parent().siblings().eq(0).html();
    alert(deptName);
    let flag = confirm('确认删除该部门么？');
    if (flag){
        $.ajax({
            url:"/dept/deleteDept",
            type:"post",
            data:{"deptName":deptName},
            dataType:"json",
            success:function (result){
                if (result === true){
                    alert("删除成功");
                    location.href = "../../../../templates/sysManage/deptManage/deptList.html";
                }else {
                    alert("删除失败");
                }
            }
        })
    }
}

function toDeptAdd(){
    location.href = "../../../../templates/sysManage/deptManage/deptAdd.html";
}
